﻿using AutoMapper.Internal.Mappers;
using EMS.system.Entityies.BaseData;
using EMS.system.IEntityAppService.BaseData.IAccountService;
using EMS.system.IEntityAppService.BaseData.IAccountService.AccountDto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using System;

namespace EMS.system.Web.Controllers.BaseData
{
    public class AccountController : Controller
    {
        private readonly IAccountAppService _accountAppService;

        public AccountController(IAccountAppService accountAppService)
        {
            _accountAppService = accountAppService;
        }

        public IActionResult AccountIndex()
        {
            return View();
        }

        public IActionResult Add(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public IActionResult AccountRole()
        {
            return View();
        }

        /// <summary>
        /// 用户新增
        /// </summary>
        /// <param name="addDto"></param>
        /// <returns></returns>
        public async Task<int> AccountAdd(AccountAddDto addDto)
        {
            return await _accountAppService.AccountAdd(addDto);
        }

        /// <summary>
        /// 显示用户
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<JsonResult> AccountRoleList(string? name, int page, int limit)
        {
            var accountRes = await _accountAppService.AccountRoleList(name, page, limit);
            return Json(new {data = accountRes.Queryable,count = accountRes.RowCount,code = 0,msg = ""});
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> AccountDel(string ids)
        {
            return await _accountAppService.AccountDel(ids);
        }

        /// <summary>
        /// 获取单个用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<AccountUpdDto> GetSingAccount(int id)
        {
            return await _accountAppService.GetSingAccount(id);
        }

        /// <summary>
        /// 编辑用户信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<int> AccountUpd(AccountUpdDto dto)
        {
            return await _accountAppService.AccountUpd(dto);
        }
    }
}
